home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / PROGRAMR / FLAT.ZIP / FLATLIST.C < prev    next >
C/C++ Source or Header  |  1993-07-09  |  15KB  |  508 lines

  1. #define WIN31
  2. #include <windows.h>
  3. /* For the fancy looking Borland dialog box routines */
  4. #ifdef USES_BWCC
  5. #include <bwcc.h>
  6. #endif
  7. #include "flatm.h"
  8. #pragma hdrstop
  9. #include <string.h>
  10. #include <stdlib.h>
  11. #include "flatdata.h"
  12. #include "flatfile.h"
  13. #include "flatsort.h"
  14. #include "flatsear.h"
  15. #include "flatadd.h"
  16. #include "\borlandc\winmem\memman.h"
  17. #include "flatlist.h"
  18. #ifdef USES_MEMCHECK
  19. /* Memory checking routines  by StratosWare Corp. */
  20. #include "\wmemchec\memcheck.h"
  21. #endif
  22.  
  23. /*--------------------------------------------
  24. -
  25. -                   FLATLIST.C
  26. -
  27. -         Displays data records in a listbox.
  28. -  Uses WIN.INI info to format the date.  Formating
  29. -        the currency is left up to you.
  30. -
  31. -               Dennis R. Fischer
  32. -                 Denam Systems
  33. -          1115 Madison St. NE  Suite 226
  34. -              Salem, Oregon  97303
  35. -
  36. -             CompuServe 70405,1422
  37. -        Internet 70405.1422@compuserve.com
  38. -
  39. -        Developed with Borland 3.1 Compiler
  40. -
  41. -     Free for the taking but please give credit
  42. -                where credit is do
  43. -
  44. ----------------------------------------------*/              
  45.  
  46.  
  47.  
  48. char ts[255];
  49.  
  50. BOOL CALLBACK _export ListProc(HWND, UINT, WPARAM, LPARAM);
  51.  
  52. void _stuffstr (char *stuffer, int loc)
  53. {
  54.     /* stuff a string into another string */
  55.  
  56.   char         s[81];
  57.   register int i, j;
  58.  
  59.   i = loc;
  60.   if (i < 0) i = 0;
  61.   j = 0;
  62.   lstrcpy (s, stuffer);
  63.   while (s[j]) {
  64.       ts[i] = s[j];
  65.       i++;
  66.       j++;
  67.   }
  68. }  /* _stuffstr */
  69.  
  70. void SetListStr(struct tagFLATDATA *Flat)
  71. {
  72.     /* Set the string that will be displayed in the
  73.          listbox to the data record
  74.   */
  75.     char ts2[15];
  76.   char ts3[5];
  77.  
  78.     /*  Price */
  79.     lstrcpy(ts2, Flat->PriceDollar);
  80.     lstrcat(ts2, ".");
  81.     lstrcat(ts2, Flat->PriceCent);
  82.     _stuffstr(ts2, 11-(lstrlen(ts2)));
  83.   /* Invoice */
  84.     _stuffstr(Flat->Invoice, 12);
  85.   /* Date */
  86.     ts2[0] = (char)0;
  87.   ts3[0] = (char)0;
  88.     switch (GetDateFormat()) {
  89.         case DayMonYear:
  90.             if ((HasDayZero()) && (atoi(Flat->Day)) < 10)
  91.                 lstrcat(ts2, "0");
  92.             lstrcat(ts2, Flat->Day);
  93.             lstrcat(ts2, GetDateMark());
  94.             if ((HasMonthZero()) && (atoi(Flat->Month) < 10))
  95.                 lstrcat(ts2, "0");
  96.             lstrcat(ts2, Flat->Month);
  97.             lstrcat(ts2, GetDateMark());
  98.             lstrcat(ts3, Flat->Year);
  99.             if (lstrlen(ts3) >= 4) {
  100.                 if (!HasCentury()) {
  101.                     ts3[0] = ts3[2];
  102.                     ts3[1] = ts3[3];
  103.           ts3[2] = (char)0;
  104.         }
  105.             }
  106.       lstrcat(ts2, ts3);
  107.             _stuffstr(ts2, 20);
  108.             break;
  109.         case YearMonDay:
  110.             lstrcat(ts2, Flat->Year);
  111.             if (lstrlen(ts2) >= 4) {
  112.                 if (!HasCentury()) {
  113.                     ts2[0] = ts2[2];
  114.                     ts2[1] = ts2[3];
  115.           ts2[2] = (char)0;
  116.         }
  117.       }
  118.             lstrcat(ts2, GetDateMark());
  119.             if ((HasMonthZero()) && (atoi(Flat->Month) < 10))
  120.                 lstrcat(ts2, "0");
  121.             lstrcat(ts2, Flat->Month);
  122.             lstrcat(ts2, GetDateMark());
  123.             if ((HasDayZero()) && (atoi(Flat->Day)) < 10)
  124.                 lstrcat(ts2, "0");
  125.             lstrcat(ts2, Flat->Day);
  126.             _stuffstr(ts2, 20);
  127.             break;
  128.         default :
  129.         /* MonDayYear */
  130.             if ((HasMonthZero()) && (atoi(Flat->Month) < 10))
  131.                 lstrcat(ts2, "0");
  132.             lstrcat(ts2, Flat->Month);
  133.             lstrcat(ts2, GetDateMark());
  134.             if ((HasDayZero()) && (atoi(Flat->Day)) < 10)
  135.                 lstrcat(ts2, "0");
  136.             lstrcat(ts2, Flat->Day);
  137.             lstrcat(ts2, GetDateMark());
  138.             lstrcat(ts3, Flat->Year);
  139.             if (lstrlen(ts3) >= 4) {
  140.                 if (!HasCentury()) {
  141.                     ts3[0] = ts3[2];
  142.                     ts3[1] = ts3[3];
  143.           ts3[2] = (char)0;
  144.         }
  145.             }
  146.       lstrcat(ts2, ts3);
  147.             _stuffstr(ts2, 20);
  148.             break;
  149.     }
  150.     /* Product */
  151.     _stuffstr(Flat->Product, 32);
  152.     /* Sold Ver */
  153.     _stuffstr(Flat->SoldVersion, 45);
  154.     /* Upgrade Ver */
  155.     _stuffstr(Flat->UpdateVersion, 50);
  156.   /* Company or Name */
  157.     if (lstrlen(Flat->Company) > 0)
  158.         _stuffstr(Flat->Company, 55);
  159.   else
  160.         _stuffstr(Flat->Name, 55);
  161.     /* State */
  162.     _stuffstr(Flat->State, 86);
  163.     /* Country */
  164.   _stuffstr(Flat->Country, 89);
  165.   ts[105] = (char)0;
  166. }  /* SetListStr */
  167.  
  168. BOOL FindStrs (LPCSTR lpFor, LPCSTR lpAt, BOOL bCaseSensitive)
  169. {
  170.     /* Look for the search string that the user
  171.          indicated he wanted to look for
  172.   */
  173.     BOOL   bFound = TRUE;
  174.   BOOL   bQuit, bQuit2;
  175.     char   LookAt[(MAXDATASTR * 2)];
  176.     char   LookFor[(MAXDATASTR * 2)];
  177.   char   LookAtSave[(MAXDATASTR * 2)];
  178.     LPSTR  pLookAt;
  179.     LPCSTR pLookFor;
  180.     LPCSTR p2p;
  181.  
  182.     if (lstrlen(lpFor) > 0) {
  183.         bFound = FALSE;
  184.         lstrcpy(LookAt, lpAt);
  185.         lstrcpy(LookFor, lpFor);
  186.         lstrcpy(LookAtSave, lpAt);
  187.         pLookAt = &LookAt[0];
  188.         if (!bCaseSensitive) {
  189.         if (LookAt[0])
  190.                 AnsiUpperBuff(LookAt, (UINT)lstrlen(LookAt));
  191.       if (LookAtSave[0])
  192.                 AnsiUpperBuff(LookAtSave, (UINT)lstrlen(LookAtSave));
  193.       if (LookFor[0])
  194.                 AnsiUpperBuff(LookFor, (UINT)lstrlen(LookFor));
  195.         }
  196.         bQuit = FALSE;
  197.         do{
  198.             lstrcpy(LookAt, LookAtSave);
  199.             pLookAt[lstrlen(LookFor)] = (char)0;
  200.             p2p = pLookAt;
  201.             pLookFor = &LookFor[0];
  202.             bQuit2=FALSE;
  203.             do{
  204.                 if (p2p[0] == pLookFor[0]){
  205.                     if (p2p[0] == (char)0) {
  206.                         bQuit2 = TRUE;
  207.                         bQuit = TRUE;
  208.                         bFound = TRUE;
  209.                     }
  210.                     else {
  211.                         p2p = AnsiNext(p2p);
  212.                         pLookFor = AnsiNext(pLookFor);
  213.                     }
  214.                 }
  215.                 else
  216.                     bQuit2 = TRUE;
  217.             }while (!bQuit2);
  218.             pLookAt = AnsiNext(pLookAt);
  219.             if (pLookAt[0] == (char)0)
  220.                 bQuit = TRUE;
  221.         }while(!bQuit);
  222.     }
  223.   return bFound;
  224. }
  225.  
  226. void ShowSales(HWND hW)
  227. {
  228.     /* Create the list box */
  229.     FARPROC fpList;
  230.  
  231.     fpList = MakeProcInstance(ListProc, GetInstance());
  232.     if (fpList) {
  233.         DialogBox(GetInstance(), "DLG_LIST", hW, fpList);
  234.         FreeProcInstance(fpList);
  235.     }
  236. }
  237.  
  238. #pragma argsused
  239. BOOL CALLBACK _export ListProc(HWND hDlg,
  240.                                UINT message,
  241.                                                              WPARAM wParam,
  242.                                                              LPARAM lParam) {
  243.     long               recnum = 0l;
  244.   BOOL               bQuit;
  245.     BOOL               bUseit;
  246.   BOOL               bGoodMem;
  247.     HFILE              fhand;
  248.     int                i;
  249.   int                dateval;
  250.     WORD               recsize;
  251.     static LRESULT     nIndex;
  252.     char               ts2[32];
  253.     LPCSTR             lpcStr;
  254.   int                dReadResult;
  255.   long               lSeekResult;
  256.   static BOOL        bNeverused;
  257.     int                nError;
  258.     struct tagFLATDATA Flat;
  259.     TEXTMETRIC         tm;
  260.     HDC                hdc;
  261.     static int         TotEntries;
  262.     int                HeapErr;
  263.   long               lBaseEntries;
  264.  
  265.   switch(message) {
  266.         case WM_INITDIALOG:
  267.             SetCursor(LoadCursor(NULL, IDC_WAIT));
  268.             bNeverused = TRUE;
  269.       /* Set the window text */
  270.             switch (GetWork()) {
  271.                 case DoEdit : SetWindowText(hDlg, "Edit Sales"); break;
  272.                 case DoNew  : SetWindowText(hDlg, "New Sale"); break;
  273.                 case DoView : SetWindowText(hDlg, "View Sales"); break;
  274.                 case DoDelete:SetWindowText(hDlg, "Delete Sale"); break;
  275.         default     : SetWindowText(hDlg, "Error"); break;
  276.             }
  277.       /* turn off OK button */
  278.             EnableWindow(GetDlgItem(hDlg, IDOK), FALSE);
  279.             /* Turn off list box redraw until everything is loaded
  280.       */
  281.             SendDlgItemMessage(hDlg, DLG_LISTBOX, WM_SETREDRAW, TRUE, 0L);
  282.             /* Make listbox use fixed-sized font so
  283.                  everything lines up.  You could use set the tabs instead.
  284.       */
  285.             SendDlgItemMessage(hDlg, DLG_LISTBOX, WM_SETFONT,
  286.                                                  GetStockObject(SYSTEM_FIXED_FONT), 0L);
  287.             /* set width (in pixels) of listbox so user can
  288.                  scroll the horizontal box
  289.             */
  290.             hdc = GetDC(hDlg);
  291.             GetTextMetrics(hdc, &tm);
  292.             SendDlgItemMessage(hDlg, DLG_LISTBOX, LB_SETHORIZONTALEXTENT,
  293.                                                  tm.tmAveCharWidth * 125, 0L);
  294.       ReleaseDC(hDlg, hdc);
  295.             /* Load list box with notices */
  296.       TotEntries=0;
  297.       SetCursor(LoadCursor(NULL, IDC_WAIT));
  298.       recnum = 0L;
  299.             recsize = (WORD)sizeof(Flat);
  300.             lBaseEntries = GetNumOfFlatRecords();
  301.       if (lBaseEntries)
  302.                 HeapErr = CreateHeap((long)(sizeof(struct tagEVENTSORT) * (lBaseEntries + 1L)),
  303.                     (int)(lBaseEntries + 1L));
  304.             if (lBaseEntries > 0L) {
  305.                 if (HeapErr == IDE_OK) {
  306.                     fhand = _lopen(flatfilename, OF_READ);
  307.                     if (fhand != -1 ) {
  308.                         ClearSortPtr();
  309.                         bQuit = FALSE;
  310.                         do{
  311.                             bQuit =